#first_name_file, middle_name_file, last_name_file, to_file = ARGV

prompt = "> "
puts "Type the file path in order to first name, middle name, last name, output:"

puts "1. Your first name file:"
print prompt
first_name_file = STDIN.gets.chomp()

puts "2. Your middle name file:"
print prompt
middle_name_file = STDIN.gets.chomp()

puts "3. Your last name file:"
print prompt
last_name_file = STDIN.gets.chomp()

puts "4. Your output name file:"
print prompt
to_file = STDIN.gets.chomp()

puts "5. Number of record generated:"
print prompt
num_red = STDIN.gets.chomp().to_i

puts "Your name are generated by three files: #{first_name_file}, #{middle_name_file}, #{last_name_file} to #{to_file} file"
if (File.exists? first_name_file) && (File.exists? middle_name_file) && (File.exists? last_name_file)
	#if exists from_file
	#read this file
	first_name = File.open(first_name_file, "rb")
	middle_name = File.open(middle_name_file, "rb")
	last_name = File.open(last_name_file, "rb")
	#fill data to data_reader with array format
	data_reader = {}
	data_reader.merge! :f => first_name.read().split()
	data_reader.merge! :m => middle_name.read().split()
	data_reader.merge! :l => last_name.read().split()

	#print out content to screen
	

	output = File.open(to_file, 'w') 

	num_red.times do |i|
		#get random value from data_reader
		f = data_reader[:f].sample
		m = data_reader[:m].sample
		l = data_reader[:l].sample

		puts "#{i+1}: #{f} #{m} #{l}"
		#write to file
		output.write "#{i+1}: #{f} #{m} #{l}\n"
	end

	#close file
	output.close()
	first_name.close()
	middle_name.close()
	last_name.close()
else
	puts "The file path does not exist. Please try again!"
end
